Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add removeRecursive and listSubTreeBFS methods #88

Merged
merged 3 commits into from
Sep 18, 2019

Conversation

lambertkuang
Copy link
Contributor

@lambertkuang lambertkuang commented Feb 27, 2019

Add methods removeAll and getAllChildren. Implementation is based off the java ZKUtil class.

Related issues: #54, #10

@lambertkuang lambertkuang changed the title Add recursive delete WIP: Add recursive delete Feb 27, 2019
@lambertkuang lambertkuang changed the title WIP: Add recursive delete Add recursive delete and list Feb 27, 2019
@lambertkuang lambertkuang changed the title Add recursive delete and list Add removeAll and getAllChildren Feb 27, 2019
@alexguan
Copy link
Owner

When it's ready to be reviewed, please squash your commit

@lambertkuang
Copy link
Contributor Author

It's ready for review, thanks!

Copy link
Contributor Author

@lambertkuang lambertkuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two notes

assert(typeof callback === 'function', 'callback must be a function.');

var self = this;
var tree = [path];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This includes the path that was passed in as part of the results, which is also what ZKUtil.listSubTreeBFS seems to do.

callback(error);
return;
}
async.eachSeries(children.reverse(), function (nodePath, next) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse is called here to remove leaf nodes first

@lambertkuang
Copy link
Contributor Author

Hey @alexguan, please review this when you get a chance

@ghostg00
Copy link

ghostg00 commented Sep 9, 2019

When to merge

@alexguan
Copy link
Owner

Overall this is a good PR, however does it belong the core zookeeper client though? It's more like an util that should exist outside the client.

index.js Outdated
* @param [version=-1] {Number} The version of the node.
* @param callback {Function} The callback function.
*/
Client.prototype.removeAll = function(path, version, callback) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the ZKUtil names better: removeRecursively, which makes it clear that it will remove the provided root node as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently named deleteRecursive (https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/ZKUtil.java#L51) but to keep the remove naming convention of this library, should I change to removeRecursive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to removeRecursive and listSubTreeBFS

index.js Outdated
* @param path {String} The node path.
* @param callback {Function} The callback function.
*/
Client.prototype.getAllChildren = function(path, callback) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to expose this method? Again, the the listSubTreeBFS is a better name even for private method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also a public method on ZKUtil. I'll rename this to listSubTreeBFS.

@lambertkuang
Copy link
Contributor Author

It would be nice to have in this library so people don't have to implement or require a separate util to have this functionality. I see that mkdirp is also included in this library, which seems in line with these two methods.

Copy link
Owner

@alexguan alexguan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks, will merge and make a new release

@alexguan alexguan merged commit 0208a2e into alexguan:master Sep 18, 2019
@alexguan alexguan changed the title Add removeAll and getAllChildren Add removeRecursive and listSubTreeBFS methods Sep 18, 2019
@lambertkuang lambertkuang deleted the remove-all branch September 19, 2019 00:25
@lambertkuang lambertkuang restored the remove-all branch September 19, 2019 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants